package com.jason.auto.repository;

import com.jason.auto.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {

    @Modifying
    @Transactional
    @Query(value = "delete from User u where u.id in (:ids) ")
    int batchDelete(@Param("ids") List<Long> ids);

    User findFirstByPhoneAndIdNot(String phone, Long id);

    User findFirstByNameAndIdNot(String name, Long id);
}
